/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: cbus_buffer.h
 *
 * Purpose: implementation a buffer wrapper for cbus
 *
 * Developer:
 *   wen.gu , 2021-06-15
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __CBUS_BUFFER_H__
#define __CBUS_BUFFER_H__

#include "cbus/core/cbus_type.h"
#include "cbus/core/cbus_error.h"

/******************************************************************************
 **    MACROS
 ******************************************************************************/

#define CBUS_BUFFER_INVALID (NULL)
/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
G_C_HEADER_START


struct _cbus_buffer;
typedef struct _cbus_buffer* cbus_buffer_t;

typedef void (*cbus_buffer_data_free_func)(void* opaque, GBUF data, GU32 size);
/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/

G_API cbus_buffer_t cbus_buffer_alloc(GU32 size);
G_API cbus_buffer_t cbus_buffer_allocz(GU32 size);
/** will be aways free old_buf and set it as 'CBUS_BUFFER_INVALID' whether realloc success or failed */
G_API cbus_buffer_t cbus_buffer_realloc(cbus_buffer_t* old_buf, GU32 new_size); 

G_API cbus_buffer_t cbus_buffer_create(GBUF data, GU32 size, cbus_buffer_data_free_func data_free, void* opaque);

G_API void cbus_buffer_default_data_free(void* opaque, GBUF data, GU32 size);
G_API void cbus_buffer_free(cbus_buffer_t buffer);


G_API cbus_buffer_t cbus_buffer_clone(cbus_buffer_t org_buf);

G_API cbus_buffer_t cbus_buffer_reference(cbus_buffer_t org_buf);

G_API GBUF cbus_buffer_data(const cbus_buffer_t buffer); 
G_API GU32 cbus_buffer_size(const cbus_buffer_t buffer); 







G_C_HEADER_END
#endif /** !__CBUS_BUFFER_H__ */

